FROM golang:1.17-alpine as builder
WORKDIR /app
COPY  . .
RUN ls; \
    go env -w GO111MODULE="on"; \
    go env -w GOPROXY="https://goproxy.cn,direct"; \
    go mod tidy; \
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o  bin/httpserver2 .

# 为方便k8s上使用，改为alpine
FROM alpine
# glog日志会自动写入tmp文件夹下面，没有将会报错 no such file or directory
# 将第一步编译结果导入
COPY --from=builder /app/bin/httpserver2 /httpserver2
EXPOSE 80
ENTRYPOINT ["/httpserver2"]